package cn.com.zetatech.loader.resolver.service.impl;

/**
 * @author jian.chen@zetatech.com.cn
 * @Description TODO
 * @Date 2024/8/26 20:01
 */
import cn.com.zetatech.loader.resolver.service.EnumFileParserStrategy;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class EnumJSONFileParser implements EnumFileParserStrategy {

    public static class Person {
        private String name;
        private int age;
        private String email;

        public Person() {
            // Default constructor needed for Jackson
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        @Override
        public String toString() {
            return "Person{name='" + name + "', age=" + age + ", email='" + email + "'}";
        }
    }

    @Override
    public List<Person> parse(String filePath) {
        ObjectMapper objectMapper = new ObjectMapper();
        List<Person> people = null;

        try {
            people = objectMapper.readValue(new File(filePath), new TypeReference<List<Person>>() {});
        } catch (IOException e) {
            e.printStackTrace();
        }

        return people;
    }
}

